#这个脚本用于复制指定位置的内容[从(x,y) 到 (x1,y2)]
#鼠标会模拟左键长按选中的动作进行复制

import pyautogui
import pyperclip
import time

def copy_text(start_pos, end_pos):
    """
    从起始位置拖拽到结束位置并复制选中内容
    
    Args:
        start_pos: 起始坐标元组 (x, y)
        end_pos: 结束坐标元组 (x1, y1)
    
    Returns:
        str: 复制到的文本内容，失败返回None
    """
    try:
        pyautogui.moveTo(start_pos[0], start_pos[1])
        time.sleep(0.1)
        pyautogui.mouseDown()
        time.sleep(0.1)
        pyautogui.moveTo(end_pos[0], end_pos[1], duration=0.2)
        time.sleep(0.1)
        pyautogui.mouseUp()
        time.sleep(0.1)
        pyautogui.hotkey('ctrl', 'c')
        time.sleep(0.2)
        
        content = pyperclip.paste()
        print(f"已复制从 {start_pos} 到 {end_pos} 的内容: {content}")
        return content
    except Exception as e:
        print(f"复制失败: {e}")
        return None

if __name__ == "__main__":
    # 输入格式示例：(908,527)
    start_pos = (908, 527)
    end_pos = (1100, 527)
    
    print("3秒后开始复制...")
    time.sleep(3)
    result = copy_text(start_pos, end_pos)
    if result:
        print(f"\n返回值: {result}")
